package de.tum.in.eist.poll.server.dao;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;

import de.tum.in.eist.poll.shared.beans.Lecture;

public class LectureDaoImpl implements LectureDaoInterface, Serializable {
	/**
	 * serialization version
	 */
	private static final long serialVersionUID = 1L;
	
	/**
	 * Map from a lecture id to a Lecture
	 */
	private TreeMap<String,Lecture> lectures =
		new TreeMap<String,Lecture>();

	@Override
	public void put(Lecture lecture) {
		lectures.put(lecture.getLectureID(), lecture);
	}

	@Override
	public Lecture get(String lectureID) {
		return lectures.get(lectureID);
	}

	@Override
	public List<Lecture> getByLecturer(String lecturerID) {
		ArrayList<Lecture> result = new ArrayList<Lecture>();
		for (Lecture lecture : lectures.values()) {
			if (lecture.getLecturerID().equals(lecturerID)) {
				result.add(lecture);
			}
		}
		return result;
	}
	
	@Override
	public boolean exists(String lectureID) {
		return lectures.containsKey(lectureID);
	}
}
